window.onload = function () {
  var x = 100,
    y = 100,
    z = 100;
  var points = [
    [
      343.05472305472324,
      450.00999000998996
    ],
    [
      506.69108669108687,
      450.00999000998996
    ],
    [
      506.69108669108687,
      293.6463536463536
    ],
    [
      343.05472305472324,
      293.6463536463536
    ],
    [
      383.9638139638141,
      399.100899100899
    ],
    [
      383.9638139638141,
      295.4645354645354
    ],
    [
      547.6001776001777,
      399.100899100899
    ],
    [
      547.6001776001777,
      295.4645354645354
    ]
  ];

  var faces = [
    [points[4], points[5], points[7], points[6]], //后0
    [points[0], points[4], points[6], points[1]], //下1
    [points[0], points[3], points[5], points[4]], //左2
    [points[1], points[2], points[7], points[6]], //右3
    [points[2], points[3], points[5], points[7]], //上4
    [points[0], points[3], points[2], points[1]], //前5
  ]

  var mutilPolygonRings = [
    [
      [
        [
          183.31288343558322,
          645.8895705521473
        ],
        [
          183.31288343558322,
          463.31288343558333
        ],
        [
          416.93251533742364,
          463.31288343558333
        ],
        [
          416.93251533742364,
          645.8895705521473
        ]
      ]
    ],
    [
      [
        [
          183.31288343558322,
          645.8895705521473
        ],
        [
          183.31288343558322,
          463.31288343558333
        ],
        [
          -38.527607361962964,
          413.31288343558333
        ],
        [
          -38.527607361962964,
          595.8895705521473
        ]
      ]
    ],
    [
      [
        [
          416.93251533742364,
          463.31288343558333
        ],
        [
          183.31288343558322,
          463.31288343558333
        ],
        [
          -38.527607361962964,
          413.31288343558333
        ],
        [
          83.1901840490798,
          413.31288343558333
        ]
      ]
    ]
  ]

  // 定义一个平行四边形
  var paralletogramRings = [[
    [650, 100], [700, 200], [1000, 200], [950, 100], [650, 100]]
  ]

  var paralletogram = new Datatang.Parallelogram(paralletogramRings)

  var mutilPolygon = new Datatang.Cube(mutilPolygonRings)

  // var features = [new Datatang.Feature(point),
  // new Datatang.Feature(line),
  // new Datatang.Feature(polygon),
  // new Datatang.Feature(holePolygon),
  // new Datatang.Feature(mutilPolygon),
  // new Datatang.Feature(paralletogram, null, '平行四边形'),
  // new Datatang.Feature(extent),
  // new Datatang.Feature(extent1)
  // ]
  var features = [new Datatang.Feature(mutilPolygon)]
  // 将会获取缺省样式
  var featureLayer = window.flayer = new Datatang.FeatureLayer()
  window.Datatang = Datatang;
  featureLayer.addFeatures(features)

  var mapextent = [0, 0, 1280, 720];
  Datatang.Cube.cubeMode = 3;
  var map = window.map = new Datatang.Map({
    layers: [
      new Datatang.SingleImageLayer({
        url: 'source/img-0000403420.png',
        imageExtent: mapextent,
        projection: {
          extent: mapextent
        }
      }),
      featureLayer
    ],
    target: 'map',
    view: new Datatang.View({
      projection: {
        extent: mapextent
      },
      center: Datatang.ExtentUtil.getCenter(mapextent),
      zoom: 2,
      maxZoom: 8
    })
  });

  // var selectedFeatures = [new Datatang.Feature(point)]

  var modifyTool = new Datatang.Modify({
  });

  map.addComponents(modifyTool)

  var typeSelect = document.getElementById('type')

  /**
   * Handle change event.
   */
  typeSelect.onchange = function () {
    var value = typeSelect.value
    if (value === 'point') {
      modifyTool.features = [new Datatang.Feature(point)]
    } else if (value === 'line') {
      modifyTool.features = [new Datatang.Feature(line)]
    } else if (value === 'polygon') {
      modifyTool.features = [new Datatang.Feature(polygon)]
    } else if (value === 'holePolygon') {
      modifyTool.features = [new Datatang.Feature(holePolygon)]
    } else if (value === 'cube') {
      modifyTool.features = [new Datatang.Feature(mutilPolygon)]
    } else if (value === 'extent') {
      modifyTool.features = [new Datatang.Feature(extent)]
    } else if (value === 'parallelogram') {
      modifyTool.features = [new Datatang.Feature(paralletogram)]
    }
  }
}

